package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {

    @Autowired
    private PaymentTypeService paymentTypeService;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
        // 调用mybatis-plus 的查询（list）方法
        List<PaymentType> paymentTypeList = paymentTypeService.list();
/*        Result<List<PaymentType>> result = Result.ok(list);
        return result;  */
        //返回查询结果
        return Result.ok(paymentTypeList);
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
        // 调用mybatis-plus的（saveOrUpdate）方法
        boolean is = paymentTypeService.saveOrUpdate(paymentType);
        //判断结果处理
        if(!is){
            return Result.fail(); //返回失败
        }
        return Result.ok(); //返回成功
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {
        // 调用mybatis-plus的（removeById）方法
        paymentTypeService.removeById(id);
        // 返回正确结果
        return Result.ok();
    }

}















